package com.liuhongwei.test.bean;


import com.liuhongwei.test.utils.PropertiesUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Constants {

    public static String AUTHER_COMMENT;
    public static Boolean IGNORE_TABLE_PERFIX;
    // 需要忽略的属性
    public static String IGNORE_BEAN_TOJSON_FILED;
    public static String IGNORE_BEAN_TOJSON_EXPRESSION;
    public static String IGNORE_BEAN_TOJSON_CLASS;
    // 日期序列化、反序列化
    public static String BEAN_DATE_FORMAT_EXPRESSION;
    public static String BEAN_DATE_FORMAT_CLASS;
    public static String BEAN_DATE_UNFORMAT_EXPRESSION;
    public static String BEAN_DATE_UNFORMAT_CLASS;

    // 查询对象相关
    public static String SUFFIX_BEAN_QUERY;
    public static String SUFFIX_BEAN_QUERY_FUZZY;
    public static String SUFFIX_BEAN_QUERY_TIME_START;
    public static String SUFFIX_BEAN_QUERY_TIME_END;
    // mappers
    public static String SUFFIX_MAPPER;
    public static String SUFFIX_MAPPER_EXTEND;

    // assemble
    public static String SUFFIX_ASSEMBLE;
    public static String PATH_BASE;
    private static String PATH_JAVA = PropertiesUtils.getProperty("main.java");
    private static String PATH_RESOURCES = PropertiesUtils.getProperty("main.source");
    public static String PACKAGE_BASE;
    // po
    public static String PACKAGE_PO;
    public static String PATH_PO;
    // 工具类
    public static String PACKAGE_UTILS;
    public static String PATH_UTILS;
    // 枚举
    public static String PACKAGE_ENUMS;
    public static String PATH_ENUMS;
    // 异常
    public static String PACKAGE_EXCEPTION;
    public static String PATH_EXCEPTION;
    // 查询
    public static String PACKAGE_QUERY;
    public static String PATH_QUERY;
    // assemble
    public static String PACKAGE_ASSEMBLE;
    public static String PATH_ASSEMBLE;
    // vo
    public static String PACKAGE_VO;
    public static String PATH_VO;
    // 映射
    public static String PACKAGE_MAPPERS;
    public static String PACKAGE_MAPPERS_EXTEND;
    public static String PATH_MAPPERS;
    public static String PATH_MAPPERS_XML;
    // 服务类
    public static String PACKAGE_SERVICE;
    public static String PATH_SERVICE;
    // 服务类实现
    public static String PACKAGE_SERVICE_IMPL;
    public static String PATH_SERVICE_IMPL;
    // controller
    public static String PACKAGE_CONTROLLER;
    public static String PATH_CONTROLLER;

    public static String NAME_TABLE;
    public static String TABLE_NOTICE;


    public static Map<String, String> sqlTypeMap = new HashMap<>();
    public static List<String> SQL_DATE_TIME_TYPES = Arrays.asList("datetime", "timestamp");
    public static List<String> SQL_DATE_TYPES = Arrays.asList("date");
    public static List<String> SQL_DECIMAL_TYPES = Arrays.asList("decimal", "double", "float");
    public static final String TYPE_STRING = "String";
    public static final String TYPE_DATE = "Date";

    static {
        AUTHER_COMMENT = PropertiesUtils.getProperty("auther.comment");
        IGNORE_TABLE_PERFIX = Boolean.valueOf(PropertiesUtils.getProperty("ignore.table.prefix"));
        // 忽略的属性
        IGNORE_BEAN_TOJSON_FILED = PropertiesUtils.getProperty("ignore.bean.tojson.filed");
        IGNORE_BEAN_TOJSON_EXPRESSION = PropertiesUtils.getProperty("ignore.bean.tojson.expression");
        IGNORE_BEAN_TOJSON_CLASS = PropertiesUtils.getProperty("ignore.bean.tojson.class");
        // 日期序列化、反序列化
        BEAN_DATE_FORMAT_EXPRESSION = PropertiesUtils.getProperty("bean.date.format.expression");
        BEAN_DATE_FORMAT_CLASS = PropertiesUtils.getProperty("bean.date.format.class");
        BEAN_DATE_UNFORMAT_EXPRESSION = PropertiesUtils.getProperty("bean.date.unformat.expression");
        BEAN_DATE_UNFORMAT_CLASS = PropertiesUtils.getProperty("bean.date.unformat.class");

        // 查询对象相关
        SUFFIX_BEAN_QUERY = PropertiesUtils.getProperty("suffix.bean.query");
        SUFFIX_BEAN_QUERY_FUZZY = PropertiesUtils.getProperty("suffix.bean.query.fuzzy");
        SUFFIX_BEAN_QUERY_TIME_START = PropertiesUtils.getProperty("suffix.bean.query.time.start");
        SUFFIX_BEAN_QUERY_TIME_END = PropertiesUtils.getProperty("suffix.bean.query.time.end");
        // mappers
        SUFFIX_MAPPER = PropertiesUtils.getProperty("suffix.mapper");
        SUFFIX_MAPPER_EXTEND = PropertiesUtils.getProperty("suffix.extend.mapper");

        SUFFIX_ASSEMBLE = PropertiesUtils.getProperty("suffix.assemble");

        PATH_BASE = PropertiesUtils.getProperty("project.dir");
        PATH_JAVA = PATH_BASE + PATH_JAVA;
        PATH_RESOURCES = PATH_BASE + PATH_RESOURCES;
        PACKAGE_BASE = PropertiesUtils.getProperty("package.base");

        // po
        PACKAGE_PO = PACKAGE_BASE + PropertiesUtils.getProperty("package.po");
        PATH_PO = PATH_JAVA + PACKAGE_PO.replace(".", "/");

        // 工具类
        PACKAGE_UTILS = PACKAGE_BASE + PropertiesUtils.getProperty("package.utils");
        PATH_UTILS = PATH_JAVA + PACKAGE_UTILS.replace(".", "/");

        // 枚举
        PACKAGE_ENUMS = PACKAGE_BASE + PropertiesUtils.getProperty("package.enums");
        PATH_ENUMS = PATH_JAVA + PACKAGE_ENUMS.replace(".", "/");

        // 枚举
        PACKAGE_EXCEPTION = PACKAGE_BASE + PropertiesUtils.getProperty("package.exception");
        PATH_EXCEPTION = PATH_JAVA + PACKAGE_EXCEPTION.replace(".", "/");

        // 查询
        PACKAGE_QUERY = PACKAGE_BASE + PropertiesUtils.getProperty("package.query");
        PATH_QUERY = PATH_JAVA + PACKAGE_QUERY.replace(".", "/");

        // VO
        PACKAGE_VO = PACKAGE_BASE + PropertiesUtils.getProperty("package.vo");
        PATH_VO = PATH_JAVA + PACKAGE_VO.replace(".", "/");

        // 查询
        PACKAGE_ASSEMBLE = PACKAGE_BASE + PropertiesUtils.getProperty("package.assemble");
        PATH_ASSEMBLE = PATH_JAVA + PACKAGE_ASSEMBLE.replace(".", "/");

        // 映射
        PACKAGE_MAPPERS = PACKAGE_BASE + PropertiesUtils.getProperty("package.mappers");
        PATH_MAPPERS = PATH_JAVA + PACKAGE_MAPPERS.replace(".", "/");
        PATH_MAPPERS_XML = PATH_RESOURCES + PACKAGE_MAPPERS.replace(".", "/");

        // 服务类
        PACKAGE_SERVICE = PACKAGE_BASE + PropertiesUtils.getProperty("package.service");
        PATH_SERVICE = PATH_JAVA + PACKAGE_SERVICE.replace(".", "/");

        // 服务类实现
        PACKAGE_SERVICE_IMPL = PACKAGE_BASE + PropertiesUtils.getProperty("package.service.impl");
        PATH_SERVICE_IMPL = PATH_JAVA + PACKAGE_SERVICE_IMPL.replace(".", "/");

        // controller
        PACKAGE_CONTROLLER = PACKAGE_BASE + PropertiesUtils.getProperty("package.controller");
        PATH_CONTROLLER = PATH_JAVA + PACKAGE_CONTROLLER.replace(".", "/");

        // sql类型映射java类型
        buildSqlTypeMap();

        NAME_TABLE = PropertiesUtils.getProperty("name.table");
        TABLE_NOTICE = PropertiesUtils.getProperty("table.notice");

    }

    private static void buildSqlTypeMap() {
        sqlTypeMap.put("datetime", TYPE_DATE);
        sqlTypeMap.put("timestamp", TYPE_DATE);
        sqlTypeMap.put("date", TYPE_DATE);
        sqlTypeMap.put("decimal", "BigDecimal");
        sqlTypeMap.put("double", "BigDecimal");
        sqlTypeMap.put("float", "BigDecimal");
        sqlTypeMap.put("char", TYPE_STRING);
        sqlTypeMap.put("varchar", TYPE_STRING);
        sqlTypeMap.put("text", TYPE_STRING);
        sqlTypeMap.put("mediumtext", TYPE_STRING);
        sqlTypeMap.put("longtext", TYPE_STRING);
        sqlTypeMap.put("int", "Integer");
        sqlTypeMap.put("tinyint", "Integer");
        sqlTypeMap.put("bigint", "Long");
    }

    public static void main(String[] args) {
        System.out.println(PACKAGE_PO);
        System.out.println(PATH_PO);
    }

}
